using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
using System.IO.IsolatedStorage;
using System.Runtime.Serialization;

using Pegasus.Diagnostics;

namespace Pegasus.Collections
{
	/// <summary>
	/// Extends the <see cref="StreamHashtable"/> and adds the ability to save and load the table
	/// from a Isolated Storage file.
	/// </summary>
	/// <seealso cref="StreamHashtable"/>
	/// <seealso cref="IsolatedStorageFile"/>
	[Obsolete( "Use the Generic class Pegasus.Collections.Generic.DictionaryAppData", false )]
	[Serializable]
	public class IsolatedStorageHashtable : StreamHashtable
	{
		// Local Instance Values
		[NonSerialized]
		private string m_storeName;

		[NonSerialized]
		private IsolatedStorageFile m_isoFile;

		/// <summary>
		/// 
		/// </summary>
		protected IsolatedStorageHashtable( SerializationInfo info, StreamingContext context ) :
			base( info, context )
		{
		}

		/// <summary>
		/// Default Constructor.
		/// </summary>
		/// <param name="storeName">The name of the isolated storage.</param>
		/// <param name="isoFile">The isolated storeage file object.</param>
		public IsolatedStorageHashtable( string storeName, IsolatedStorageFile isoFile ) :
			base( new IsolatedStorageFileStream( storeName, FileMode.OpenOrCreate, 
				FileAccess.ReadWrite, FileShare.None, isoFile ) )
 		{
			ParamCode.AssertNotEmpty( storeName, "storeName" );
			ParamCode.AssertNotNull( isoFile, "isoFile" );

			m_storeName = storeName;
			m_isoFile = isoFile;
		}

		/// <summary>
		/// 
		/// </summary>
		public string StoreName
		{
			get
			{
				return m_storeName;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public IsolatedStorageFile IsolatedStorageFile
		{
			get
			{
				return m_isoFile;
			}
		}
	}
}
